package model.menupages;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import view.Master;
import view.menuelements.MenuButton;
import view.menuelements.Menupanel;
import controller.Heytetrisapplication;

public class Hauptmenu extends JFrame {

	private MenuButton highscorebutton = new MenuButton("", 150, 50);
	private MenuButton newgamebutton = new MenuButton("", 200, 100);
	private MenuButton creditbutton = new MenuButton("", 150, 50);
	private Hauptmenu hauptmenu = this;

	public Hauptmenu() throws HeadlessException {
		super();
		Master.setStandardpageOptions(this);
		Master.addCloseButton(this);

		// Centerpanel
		Menupanel centerpanel = new Menupanel();
		URL ressource1 = ClassLoader.getSystemResource("ueberschrift_neu.png");
		Icon icon1 = new ImageIcon(ressource1);
		JLabel centerpic = new JLabel(icon1);
		centerpanel.add(centerpic);
		add(centerpanel, BorderLayout.CENTER);

		// untere Navigationsleiste
		Menupanel bottompanel = new Menupanel();
		URL ressource2 = ClassLoader.getSystemResource("CREDITS.png");
		URL ressource3 = ClassLoader.getSystemResource("HIGHSCORE.png");
		URL ressource4 = ClassLoader.getSystemResource("NEW GAME.png");
		newgamebutton.setFont(new Font("Dialog", Font.BOLD, 25));
		newgamebutton.setIcon(new ImageIcon(ressource4));
		highscorebutton.setIcon(new ImageIcon(ressource3));
		creditbutton.setIcon(new ImageIcon(ressource2));
		bottompanel.add(highscorebutton);
		bottompanel.add(newgamebutton);
		bottompanel.add(creditbutton);

		// fügt actionlistener zu den Buttons, die auf Drücken der Buttons
		// reagieren
		actionlistenerhinzufueg();
		add(bottompanel, BorderLayout.SOUTH);

		Master.setPageVisible(this);
	}

	private void actionlistenerhinzufueg() {
		highscorebutton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Heytetrisapplication.highscorepushed();
				Master.setPageInvisible(hauptmenu);
			}
		});

		newgamebutton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Heytetrisapplication.newgamepushed();
				Master.setPageInvisible(hauptmenu);
			}
		});

		creditbutton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Heytetrisapplication.creditpushed();
				Master.setPageInvisible(hauptmenu);
			}
		});

	}
}
